/*
 * Copyright (C) 2011  John Lawrence thegordo.john at gmail.com
 * Licensed under GPLv3 or later. see http://www.gnu.org/copyleft/gpl.html
 */

package org.jklawrencefam.server.smtp.command;

import org.jklawrencefam.annotation.smtp.SmtpCommandMarker;
import org.jklawrencefam.model.email.Address;
import org.jklawrencefam.server.smtp.SmtpCode;

/**
 * User: John Lawrence
 * Date: 6/9/11
 * Time: 11:31 PM
 */
@SmtpCommandMarker(Recipient.NAME)
public class Recipient extends SmtpCommand {
    public static final String NAME = "RCPT";

    private Address address;

    protected Recipient(String CommandString) {
        super(CommandString);
    }

    @Override
    public String getReplyMessage() {
        return composeMessage(SmtpCode.OK);
    }

    @Override
    protected boolean isValid() {
        return address != null && address.isValid();
    }

    @Override
    protected void processArgumentString() {
        // TODO : If not a local user, fail if not a valid address.
        address = new Address(argumentString);
    }

    @Override
    protected void doProcessInternal() {
        state.addRecipient(address);
    }
}
